//
//  HLiveTopAudienceView.m
//  linktuIOS
//
//  Created by hejunsong on 17/1/13.
//  Copyright © 2017年 tianxie. All rights reserved.
//

#import "HLiveTopAudienceView.h"
#import "Masonry.h"
#import "AudienceIconCell.h"
@interface HLiveTopAudienceView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong) UICollectionView *collectView;

@end

@implementation HLiveTopAudienceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self makeUI];
        
    }
    return self;
}
-(void)makeUI
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    _collectView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
    _collectView.delegate = self;
    _collectView.dataSource = self;
    _collectView.backgroundColor = [UIColor clearColor];
    layout.itemSize = CGSizeMake(36, 36);
    _collectView.showsHorizontalScrollIndicator = NO;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 2;
    
    [_collectView registerNib:[UINib nibWithNibName:@"AudienceIconCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"audience"];
    _collectView.showsHorizontalScrollIndicator = NO;
     _collectView.showsVerticalScrollIndicator = NO;
    
    
    [self addSubview:_collectView];
    
    [_collectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.bottom.mas_equalTo(self.mas_bottom).offset(0);
        make.top.mas_equalTo(self.mas_top).offset(0);
    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.viewmodel.viewerModelArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AudienceIconCell *cell =  [_collectView dequeueReusableCellWithReuseIdentifier:@"audience" forIndexPath:indexPath];
    cell.user = self.viewmodel.viewerModelArray[indexPath.row];
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.delegtae && [self.delegtae respondsToSelector:@selector(topAudienceView:index:)])
    {
        [self.delegtae topAudienceView:self index:indexPath.row];
    }
}


-(void)relaodData
{
    [self.collectView reloadData];
}
-(void)dealloc
{
    NSLog(@"dealloc --TopAudiceView");
    
}
@end
